﻿// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>

int main()
{

	//ping命令
	char sysBuf[300] = { 0 };
	//ping值大小
	char n_size[200] = { '3','2','\0' };
	//设置的ip地址
	char myIP[200] = {0};
	bool isOut = false;


	while(!isOut){
		std::cout << "*********************************************************************\n";
	std::cout << "0.更改Ping发送包大小\n";
	std::cout << "1.ping 172.169.10.1\n";
	std::cout << "5.ping 172.169.10.5\n";
	std::cout << "6.ping 172.169.10.6\n";
	std::cout << "7.ping 172.169.10.7\n";
	std::cout << "8.ping 172.169.10.8\n";
	std::cout << "9.ping 172.169.10.9\n";
	std::cout << "64.ping 172.169.10.64\n";
	std::cout << "65.ping 172.169.10.65\n";
	std::cout << "66.ping 172.169.10.66\n";
	std::cout << "67.ping 172.169.10.67\n";
	std::cout << "98.ping 172.169.10.98\n";
	std::cout << "31.设置本地连接IP为自动选择\n";
	std::cout << "32.设置本地连接静态IP为输入值\n";
	std::cout << "33.设置本地连接静态IP为172.169.10.33\n";
	std::cout << "34.设置Wifi连接IP为自动选择\n";
	std::cout << "35.设置WIFI静态IP为输入值\n";
	std::cout << "36.设置WIFI静态IP为172.169.10.36\n";
	std::cout << "37.设置USB网口连接IP为自动选择\n";
	std::cout << "38.设置USB网口静态IP为输入值\n";
	std::cout << "39.设置USB网口静态IP为172.169.10.39\n";
	std::cout << "*********************************************************************\n";

		std::cout << "\n\n请输入您的选择:";
	
	int chooseID;
	std::cin >> chooseID;
	system("cls");
		switch (chooseID) {
		case 0:
			std::cout << "请输入Ping发送包大小（Byte）: ";
			std::cin >> n_size;
			continue;
			//break;
		case 1:
			sprintf_s(sysBuf, "ping 172.169.10.1 -t -l %s", n_size);
			std::cout << sysBuf;
			system(sysBuf);
			break;
		case 5:
			sprintf_s(sysBuf, "ping 172.169.10.5 -t -l %s", n_size);
			system(sysBuf);
			break;
		case 6:
			sprintf_s(sysBuf, "ping 172.169.10.6 -t -l %s", n_size);
			system(sysBuf);
			break;
		case 7:
			sprintf_s(sysBuf, "ping 172.169.10.7 -t -l %s", n_size);
			system(sysBuf);
			break;
		case 8:
			sprintf_s(sysBuf, "ping 172.169.10.8 -t -l %s", n_size);
			system(sysBuf);
			break;
		case 9:
			sprintf_s(sysBuf, "ping 172.169.10.9 -t -l %s", n_size);
			system(sysBuf);
			break;
		case 64:
			sprintf_s(sysBuf, "ping 172.169.10.64 -t -l %s", n_size);
			system(sysBuf);
			break;
		case 65:
			sprintf_s(sysBuf, "ping 172.169.10.65 -t -l %s", n_size);
			system(sysBuf);
			break;
		case 66:
			sprintf_s(sysBuf, "ping 172.169.10.66 -t -l %s", n_size);
			system(sysBuf);
			break;
		case 67:
			sprintf_s(sysBuf, "ping 172.169.10.67 -t -l %s", n_size);
			system(sysBuf);
			break;
		case 31:
			//netsh interface ip set address name = "无线网络连接" source = dhcp
			//	netsh interface ip set dns name = "无线网络连接" source = dhcp

			//netsh interface ip set address name = "Local Area Connection" source = dhcp
				//netsh interface ip delete dns "Local Area Connection" all
				//ipconfig / flushdns
				//ipconfig / all

			system("netsh interface ip set address name = \"本地连接\" source = dhcp");
			system("netsh interface ip set dns name = \"本地连接\" source = dhcp");

			isOut = true;
			break;
		case 32:
			std:: cout << "正在设置本地连接的静态IP，请输入ip地址：";
			std::cin >> myIP;
			sprintf_s(sysBuf, "netsh interface ip set address name = \"本地连接\" source=\"static\" addr=\"%s\" mask=\"255.255.255.0\" gateway=\"172.169.10.1\" gwmetric=\"1\"", myIP);
			system(sysBuf);

			isOut = true;
			break;
		case 33:
			//本地静态ip为33
			system("netsh interface ip set address name=\"本地连接\" source=\"static\" addr=\"172.169.10.33\" mask=\"255.255.255.0\" gateway=\"172.169.10.1\" gwmetric=\"1\"");
			
			isOut = true;
			break;
		case 34:
			system("netsh interface ip set address name = \"WLAN\" source = dhcp");
			system("netsh interface ip set dns name = \"WLAN\" source = dhcp");

			isOut = true;
			break;
		case 35:
			std::cout << "正在设置Wifi网卡的静态IP，请输入ip地址：";
			std::cin >> myIP;
			sprintf_s(sysBuf, "netsh interface ip set address name = \"WLAN\" source=\"static\" addr=\"%s\" mask=\"255.255.255.0\" gateway=\"172.169.10.1\" gwmetric=\"1\"", myIP);
			system(sysBuf);

			isOut = true;
			break;
		case 36:
			//wifi的ip为36
			system("netsh interface ip set address name=\"WLAN\" source=\"static\" addr=\"172.169.10.36\" mask=\"255.255.255.0\" gateway=\"172.169.10.1\" gwmetric=\"1\"");

			break;
		case 37:
			system("netsh interface ip set address name = \"USB网口\" source = dhcp");
			system("netsh interface ip set dns name = \"USB网口\" source = dhcp");

			isOut = true;
			break;
		case 38:
			std::cout << "正在设置USB网口的静态IP，请输入ip地址：";
			std::cin >> myIP;
			sprintf_s(sysBuf, "netsh interface ip set address name = \"USB网口\" source=\"static\" addr=\"%s\" mask=\"255.255.255.0\" gateway=\"172.169.10.1\" gwmetric=\"1\"", myIP);
			system(sysBuf);

			isOut = true;
			break;
		case 39:
			//本地静态ip为33
			system("netsh interface ip set address name=\"USB网口\" source=\"static\" addr=\"172.169.10.39\" mask=\"255.255.255.0\" gateway=\"172.169.10.1\" gwmetric=\"1\"");
			
			isOut = true;
			break;
		default:
			std::cout << "无当前选项！！！ \n请重新输入您的选择：\n\n";
			continue;
			//break;

		};
	};




	std::cout << "设置成功！";
	system("pause");
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件，或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来，若要再次打开此项目，请转到“文件”>“打开”>“项目”并选择 .sln 文件
